/*
 * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.semagia.atomico.server.storage.impl;

import com.semagia.atomico.MediaType;
import com.semagia.atomico.dm.IWritableRepresentation;
import com.semagia.atomico.server.dm.ICollectionInfo;
import com.semagia.atomico.server.dm.IFragmentInfo;
import com.semagia.atomico.server.dm.ISnapshotInfo;
import com.semagia.atomico.server.storage.IStorage;
import com.semagia.atomico.server.storage.SortOrder;
import com.semagia.atomico.server.storage.StorageException;

/**
 * {@link IStorage} implementation that delegates all method invocations to
 * an underlying storage.
 * 
 * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 */
public class DelegatingStorage implements IStorage {

    /**
     * The storage implementation to which all methods are delegated to.
     */
    protected final IStorage _storage;

    /**
     * Initializes a new instance with the specified storage.
     *
     * @param storage The storage to delagte to.
     */
    public DelegatingStorage(final IStorage storage) {
        if (storage == null) {
            throw new IllegalArgumentException("The storage must not be null");
        }
        _storage = storage;
    }

    /**
     * Returns the underlying {@link IStorage}.
     *
     * @return The wrapped storage, never <tt>null</tt>.
     */
    public IStorage getWrapped() {
        return _storage;
    }

    @Override
    public ICollectionInfo getCollectionInfo(final String collectionId)
            throws StorageException {
        return _storage.getCollectionInfo(collectionId);
    }

    @Override
    public Iterable<? extends ICollectionInfo> getCollectionInfos(final SortOrder sortOrder)
            throws StorageException {
        return _storage.getCollectionInfos(sortOrder);
    }

    @Override
    public IWritableRepresentation getFragment(final String collectionId,
            String fragmentId, MediaType mediaType) throws StorageException {
        return _storage.getFragment(collectionId, fragmentId, mediaType);
    }

    @Override
    public IFragmentInfo getFragmentInfo(final String collectionId, final String fragmentId)
            throws StorageException {
        return _storage.getFragmentInfo(collectionId, fragmentId);
    }

    @Override
    public Iterable<IFragmentInfo> getFragmentInfos(final String collectionId,
            SortOrder sortOrder) throws StorageException {
        return _storage.getFragmentInfos(collectionId, sortOrder);
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.server.storage.IStorage#getFragmentInfos(java.lang.String)
     */
    @Override
    public Iterable<? extends IFragmentInfo> getFragmentInfos(String collectionId)
            throws StorageException {
        return _storage.getFragmentInfos(collectionId);
    }

    @Override
    public IWritableRepresentation getSnapshot(final String collectionId,
            String snapshotId, MediaType mediaType) throws StorageException {
        return _storage.getSnapshot(collectionId, snapshotId, mediaType);
    }

    @Override
    public ISnapshotInfo getSnapshotInfo(final String collectionId, final String snapshotId)
            throws StorageException {
        return _storage.getSnapshotInfo(collectionId, snapshotId);
    }

    @Override
    public Iterable<ISnapshotInfo> getSnapshotInfos(final String collectionId,
            final SortOrder sortOrder) throws StorageException {
        return _storage.getSnapshotInfos(collectionId, sortOrder);
    }

    @Override
    public Iterable<? extends ISnapshotInfo> getSnapshotInfos(String collectionId)
            throws StorageException {
        return _storage.getSnapshotInfos(collectionId);
    }

    @Override
    public boolean isModifiable() {
        return _storage.isModifiable();
    }

    @Override
    public long lastCollectionModification(final String collectionId)
            throws StorageException {
        return _storage.lastCollectionModification(collectionId);
    }

    @Override
    public long lastFragmentModification(final String collectionId)
            throws StorageException {
        return _storage.lastFragmentModification(collectionId);
    }

    @Override
    public long lastModification() throws StorageException {
        return _storage.lastModification();
    }

    @Override
    public long lastSnapshotModification(final String collectionId)
            throws StorageException {
        return _storage.lastSnapshotModification(collectionId);
    }

}
